package ModelLayer;

import java.util.ArrayList;
import java.util.Date;

public class Invoice {
	private static double deliveryFee = 45;
	private static double cashOnDelivery = 25;
	private int invoiceNo;
	private Date payDate;
	private double totalPrice;
	private boolean isDelivery;
	private boolean isCashOnDelivery;
	private Customer customer;
	private ArrayList<Sale> sales;

	public Invoice(int invoiceNo) {
		this.invoiceNo = invoiceNo;
		setDelivery(false);
		setCashOnDelivery(false);
	}

	public Invoice() {
		setDelivery(false);
		setCashOnDelivery(false);
	}

	public void calculatePrice() {
		double totalPrice = 0;
		for (Sale sale : sales) {
			totalPrice = totalPrice + sale.getTotalPrice();
		}
		if (isDelivery && customer.getDiscount().getDiscountId() == 2
				&& totalPrice >= customer.getDiscount().getMinPriceRequired()) {
		} else if (isDelivery) {
			totalPrice = totalPrice + deliveryFee;
			if (isCashOnDelivery) {
				totalPrice = totalPrice + cashOnDelivery;
			}
		}
		setTotalPrice(totalPrice);
	}

	public int getInvoiceNo() {
		return invoiceNo;
	}

	public void setInvoiceNo(int invoiceNo) {
		this.invoiceNo = invoiceNo;
	}

	public Date getPayDate() {
		return payDate;
	}

	public void setPayDate(Date payDate) {
		this.payDate = payDate;
	}

	public double getTotalPrice() {
		return totalPrice;
	}

	public void setTotalPrice(double totalPrice) {
		this.totalPrice = totalPrice;
	}

	public boolean isDelivery() {
		return isDelivery;
	}

	public void setDelivery(boolean isDelivery) {
		this.isDelivery = isDelivery;
	}

	public boolean isCashOnDelivery() {
		return isCashOnDelivery;
	}

	public void setCashOnDelivery(boolean isCashOnDelivery) {
		this.isCashOnDelivery = isCashOnDelivery;
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public static double getDeliveryFee() {
		return deliveryFee;
	}

	public static void setDeliveryFee(double deliveryFee) {
		Invoice.deliveryFee = deliveryFee;
	}

	public static double getCashOnDelivery() {
		return cashOnDelivery;
	}

	public static void setCashOnDelivery(double cashOnDelivery) {
		Invoice.cashOnDelivery = cashOnDelivery;
	}

	public ArrayList<Sale> getSales() {
		return sales;
	}

	public void setSales(ArrayList<Sale> sales) {
		this.sales = sales;
	}

}
